﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SPN.Layouts.SPN.pages
{
    public partial class Settings : LayoutsPageBase
    {
        #region PageEvents
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SPWeb _Web = SPContext.Current.Web;
                tb_ConfirmationUrl.Text = Common.Helper.GetWebProperty(_Web, Common.Helper._SPN_ConfirmationUrl);
                tb_SubscribeEmailFrom.Text = Common.Helper.GetWebProperty(_Web, Common.Helper._SPN_SubscribeEmailFrom);
                tb_SubscribeEmailSubject.Text = Common.Helper.GetWebProperty(_Web, Common.Helper._SPN_SubscribeEmailSubject);
                tb_SubscribeEmailContent.Text = Common.Helper.GetWebProperty(_Web, Common.Helper._SPN_SubscribeEmailContent);
                tb_SubscribeEmailLinkText.Text = Common.Helper.GetWebProperty(_Web, Common.Helper._SPN_SubscribeEmailLinkText);
                tb_UnSubscribeEmailFrom.Text = Common.Helper.GetWebProperty(_Web, Common.Helper._SPN_UnSubscribeEmailFrom);
                tb_UnSubscribeEmailSubject.Text = Common.Helper.GetWebProperty(_Web, Common.Helper._SPN_UnSubscribeEmailSubject);
                tb_UnSubscribeEmailContent.Text = Common.Helper.GetWebProperty(_Web, Common.Helper._SPN_UnSubscribeEmailContent);
                tb_UnSubscribeEmailLinkText.Text = Common.Helper.GetWebProperty(_Web, Common.Helper._SPN_UnSubscribeEmailLinkText);
                hl_Cancel.NavigateUrl = _Web.Url + "/_layouts/settings.aspx";
            }
        }
        #endregion

        #region ControlEvents
        protected void lib_Save_Click(object sender, EventArgs e)
        {
            SPWeb _Web = SPContext.Current.Web;
            _Web.AllProperties[Common.Helper._SPN_ConfirmationUrl] = tb_ConfirmationUrl.Text;
            _Web.AllProperties[Common.Helper._SPN_SubscribeEmailFrom] = tb_SubscribeEmailFrom.Text;
            _Web.AllProperties[Common.Helper._SPN_SubscribeEmailSubject] = tb_SubscribeEmailSubject.Text;
            _Web.AllProperties[Common.Helper._SPN_SubscribeEmailContent] = tb_SubscribeEmailContent.Text;
            _Web.AllProperties[Common.Helper._SPN_SubscribeEmailLinkText] = tb_SubscribeEmailLinkText.Text;
            _Web.AllProperties[Common.Helper._SPN_UnSubscribeEmailFrom] = tb_UnSubscribeEmailFrom.Text;
            _Web.AllProperties[Common.Helper._SPN_UnSubscribeEmailSubject] = tb_UnSubscribeEmailSubject.Text;
            _Web.AllProperties[Common.Helper._SPN_UnSubscribeEmailContent] = tb_UnSubscribeEmailContent.Text;
            _Web.AllProperties[Common.Helper._SPN_UnSubscribeEmailLinkText] = tb_UnSubscribeEmailLinkText.Text;
            _Web.Update();
            Response.Redirect(_Web.Url + "/_layouts/settings.aspx");
        }
        #endregion
    }
}
